package fr.afcepf.atod12.projet1.dao.tests;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import fr.afcepf.atod12.projet1.entities.Evenement;
import fr.afcepf.atod12.projet1.entities.Medecin;
import fr.afcepf.atod12.projet1.entities.Patient;
import fr.afcepf.atod12.projet1.entities.TypeEvenement;
import fr.afcepf.atod12.projet1.facades.IFacadeServices;



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/mySpringConf.xml"})
@TransactionConfiguration(transactionManager="txManager",defaultRollback=false) 
@Transactional
public class TestFacades extends TestCase{
	
	@Autowired
	@Qualifier("facadeService")
	private IFacadeServices facade;
	
//	@Test
//	public void testGetPatientByName() {
//		List<Patient> listePatient = facade.getServicePersonne().getPatientByName("pa");
//		
//		for(Patient pers : listePatient){
//			System.out.println(pers);
//		}
//	}
	
//	@Test
//	public void testGetAllTypeEvenement() {
//		List<TypeEvenement> listeTypeEvenement = facade.getServiceEvenement().getAllTypeEvenement();
//		
//		for(TypeEvenement te : listeTypeEvenement){
//			System.out.println(te.getLibelleTypeEvenement());
//		}
//	}
	
	@Test
	public void testSetEvenement() throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date d = sdf.parse("2011-07-06");
		Evenement ev = new Evenement();
		Patient p = new Patient();
		p.setNom("patient7");
		p.setPrenom("prenom");
		ev.setPatient(p);
		ev.setDateEvenement(d);
		ev.setHeureDebut("13");
		ev.setHeureFin("14");
		Medecin m = new Medecin();
		m.setIdMedecin(1);
		ev.getMedecins().add(m);
		TypeEvenement te = new TypeEvenement();
		te.setIdTypeEvenement(1);
		ev.setTypeEvenement(te);
		facade.getServiceEvenement().creationEvenement(ev);
	}
}
